{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=100\n",
    "b=1.2\n",
    "c=0b00010\n",
    "d=0xa0\n",
    "e='abc'\n",
    "f=\"xyz023\"\n",
    "g=\"\"\"\n",
    "1\n",
    "2\n",
    "4\n",
    "abcdr ui\n",
    "\"text string\"\n",
    "\"\"\"\n",
    "h='''\n",
    ".\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "i=\"\\\"\"#\\是转义字符,“”是界定字符，用于表示边界，加上\\用于表示自己，描述“引号”；\n",
    "                                                   #   字符串必须放在界定符之内"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\"'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"\n"
     ]
    }
   ],
   "source": [
    "print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (<ipython-input-8-3e8f84907914>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-8-3e8f84907914>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    i=\"'''''''''\"'''''''\"\u001b[0m\n\u001b[1;37m                         ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "i=\"'''''''''\"'''''''\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#双引号里面想要用双引号，需要用转义字符进行转义，怕出错的用单引号，必须用双引号的，需要转义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#字符串和数字是最常用的数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "k='123'#单引号表示字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "k=\"\"\"1\n",
    "2\n",
    "3\n",
    "\"\"\"#三双引号可跨行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "k='''1\n",
    "2\n",
    "3\n",
    "'''#三单引号也可以跨行使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "path=\"c:\\nt\"#路径是C盘下的nt目录，但是由于\\的存在，\n",
    "                        # \\是转义字符，恰好有\\n代表换行，所以需要让\\不转义，\n",
    "                       # 【两种方法：1.再加一个\\，2.加r前缀】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c:\n",
      "t\n"
     ]
    }
   ],
   "source": [
    "print(path)#\\n表示换行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "path=\"c:\\\\nt\"#再加一个\\的意思是前面\\为转义字符，\n",
    "            # 将后面\\的转义为反斜杠而不是原来的转义字符的意思了，这样后面的\\就不会再作用到n了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c:\\nt\n"
     ]
    }
   ],
   "source": [
    "print(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "path=r\"c:\\nt\"#前缀r的意思为原始的字符串，即：把里面所有的字符当作普通字符对待"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c:\\nt\n"
     ]
    }
   ],
   "source": [
    "print(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\\的用法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 当使用\\描述路径时经常会出现转义的情况，所以需要加r前缀来解决此类问题；\n",
    "# 在使用三引号时是需要换行符的，那时候可以不加r，加了的话三引号就不起作用了\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#转义字符：\\\\,前面转后面，输出为一个\\\n",
    "#转义字符：\\t，键盘上的Tab键,tab用于对齐用。tab的字符可以自己设置\n",
    "#转义字符：\\n，换行符\n",
    "#转义字符：\\',\\\",描述单引号和双引号，在引号内部出现单引号双引号时，需要用转义字符来描述。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "str1=\"asdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n",
    "aaaaaaaaaaaaaaaaaaaaaasdd\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "asdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdd\n"
     ]
    }
   ],
   "source": [
    "print(str1)#续行的\\,需要续行的反斜杠之后除了换行不能加任何东西了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#标识符：python中一般情况下，小写字母写标识符，特殊场景下用大写字母写标识符，\n",
    "                                                                  # 更特殊的时候才用下划线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a='123'#变量只能以字母和下划线开头，不能以数字开头；但是不推荐用下划线开头，\n",
    "                                                     # 因为下划线开头有特殊含义，不能乱用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "A='456'#每一个标识符被使用之前必须被赋值,否则名称错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "456\n"
     ]
    }
   ],
   "source": [
    "print(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'x' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-50-6fcf9dfbd479>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'x' is not defined"
     ]
    }
   ],
   "source": [
    "x#每一个标识符被使用之前必须被赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#常量：python中无法定义常量，万物皆可改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "x='abc'# 赋值即定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "x=123# 123字面常量;给x赋值叫做变量定义，变量名就是标识符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a1\n"
     ]
    }
   ],
   "source": [
    "print('a' + str(1))# 字符串无法与数字直接相加，\n",
    "                  # python用str强制让数字1变成字符串进行拼接得到：a1    强弱类型是个相对概念"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
